<?php

class BizQuery {
	
	
	static function getyjapi($company){
		
		if(empty($company)){
			return false;
		}
		$info = BizQuery::getCache($company);
		
		if($info){
			return json_decode($info['detail'],true);
		}
		$url = "http://i.yjapi.com/ECI/GetDetailsByName";
// 		$content = file_get_contents('http://i.yjapi.com/ECI/GetDetailsByName?key=9652a6e420c04db989572d8de52b37af&keyword=厦门互云网络科技有限公司');
		$content = file_get_contents('http://i.yjapi.com/ECI/GetDetailsByName?key=a9c565f252e64feb824c0d489806cc7b&keyword='.$company);
// 		print_r($content);
// 		$content = file_get_contents(APP_PATH.'bizquery1.txt2');

		$return = json_decode($content,true);
		if($return['Status']=='200'){
			$ob = M('csl_bizdetail');
			$ob->add(array(
				"company"	=> $company,
				"ctime"		=> date('Y-m-d H:i:s'),
				"detail"	=> $content,
			));
			return $return;
		}
		return false;
	}
	
	static function getCache($company){
	    $oneweek = date('Y-m-d H:i:s', strtotime('-1 week'));
	    
		$ob = M('csl_bizdetail');
		$info = $ob->where(array('company'=>$company,'ctime'=>array('egt',$oneweek)))->order(array('bizid'=>'desc'))->find();
		
		if($info){
			return $info;
		}else{
			return false;
		}
	}
}